# -*- coding: utf8 -*-
import sqlite3
from uniform_filters import uniform_filters
from gauss_filters import gauss_filters
from statistic_filters import statistic_filters
import file_control
import os
import string

#създаваме базата
conn = sqlite3.connect(r"F:\Filter Experimet\Results DB\texture_filter_experiment.db")
c = conn.cursor()

###########################################
# IMAGES
###########################################

original_dirs = [
#{'DIR' : 'F:/Filter Experimet/Texture Datasets/Set 1',
#'SET' : 1,
#},
{'DIR' : 'F:/Filter Experimet/Texture Datasets/Set 2',
'SET' : 2,
},
]

#данни за изображението
#id INTEGER PRIMARY KEY, data_set INTEGER, name VARCHAR(50), width INTEGER, height INTEGER
c = conn.cursor()
c.execute('SELECT max(id) + 1 from images',{})
row = c.fetchone()
i = row[0]
if not i:
	i = 1
	
rows = []
for root_directory in original_dirs:
	os.chdir(root_directory['DIR'])
	for file_name in os.listdir("."):
		ext = file_name[-4:]
		if os.path.isfile(root_directory['DIR']+"/"+file_name) and ext != '.csv':
			print file_name
			img = file_control.import_file(root_directory['DIR'], file_name)
			rows.append((i, root_directory['SET'], file_name.replace(ext,''), img.size[0], img.size[1]))
			i = i + 1

c = conn.cursor()
c.executemany('insert into images values (?,?,?,?,?)', rows )
conn.commit()
